<!DOCTYPE html>
<html>
	<head th:include="/common/head :: head">
		<meta charset="UTF-8">
		<meta name="renderer" content="webkit|ie-comp|ie-stand">
		<meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
		<meta name="viewport" content="width=device-width,user-scalable=yes, minimum-scale=0.4, initial-scale=0.8,target-densitydpi=low-dpi" />
		<meta http-equiv="Cache-Control" content="no-siteapp" />
	</head>
<body>
	<div class="x-body">
		<form class="layui-form" lay-filter="update_form">
			<div class="layui-form-item">
				<label for="id" class="layui-form-label">计划编码</label>
				<div class="layui-input-inline">
					<input type="text" id="id" name="id" required=""
						lay-verify=id autocomplete="off" class="layui-input" readOnly="readOnly">
				</div>
			</div>
			<div class="layui-form-item">
				<label for="userName" class="layui-form-label">计划人姓名</label>
				<div class="layui-input-inline">
					<input type="text" id="userName" name="userName" required=""
						lay-verify=userName autocomplete="off" class="layui-input"
						readOnly="readOnly">
				</div>
			</div>
			<div class="layui-form-item">
				<label for="month" class="layui-form-label">计划月份</label>
				<div class="layui-input-inline">
					<input type="text" id="month" name="month" required=""
						lay-verify="month" autocomplete="off" class="layui-input" readOnly="readOnly">
				</div>
			</div>
			<div class="layui-form-item">
				<label for="status" class="layui-form-label">计划状态</label>
				<div class="layui-input-inline">
					<input type="text" id="status" name="status" required=""
						lay-verify=status autocomplete="off" class="layui-input"
						readOnly="readOnly">
				</div>
			</div>
			<div class="layui-form-item layui-form-text">
              	<label for="content" class="layui-form-label">计划内容</label>
              <div class="layui-input-block">
                  <textarea  id="content" name="content" autocomplete="off" class="layui-textarea" readOnly="readOnly"></textarea>
              </div>
          </div>
			<div class="layui-form-item">
				<label for="L_repass" class="layui-form-label"> </label>
				<a class="layui-btn" onclick="sub(this)" status="2">通过</a>
				<a class="layui-btn" onclick="sub(this)" status="3">驳回</a>
			</div>
		</form>
	</div>
</body>
</html>
<script>
	$(function(){
		//初始化
		init();
		
	})
	var planId = sessionStorage.getItem("planId");
	var _this = {};
	//通过id拿到对象
	function init(){
		$.post("/plan/getPlanById","planId="+planId,function(result){
			if(result.status==0){
				//初始化修改表单（赋值）
				initUpdateForm(result.data);
			}else{
				layer.msg(result.msg);
			}
		})
	}
	//初始化修改表单（赋值）
	function initUpdateForm(plan){
		layui.use(['form','layer'],function(){
			$=layui.jquery;
			var form = layui.form,
			layer = layui.layer;
			//赋值
			form.val('update_form',{
				"id":plan.id,
				"userName":plan.userName,
				"month":plan.month,
				"content":plan.content
			})
			if(plan.status==1){
				form.val("update_form",{
					"status":"未审核"
				})
			}
			if(plan.status==2){
				form.val("update_form",{
					"status":"已通过"
				})
			}else{
				form.val("update_form",{
					"status":"未通过"
				})
			}
		})
	}
	//提交修改操作
	function sub(ele){
		var status= $(ele).attr("status");
		$.ajax({
			url:"/plan/updateStatus",
			type:"post",
			data:{
				"status":status,
				"id":planId
				},
			success:function(result){
				if(result.status==0){
					layer.msg(result.msg,function(){
						//关闭弹出层
						var index = parent.layer.getFrameIndex(window.name);
						parent.layer.close(index);
					})
				}else{
					layer.msg(result.msg);
				}
			}
		})
	}
	
</script>
